home *** CD-ROM | disk | FTP | other *** search
- /*
- CDTrack - An XFCN to report the number of tracks
- ©Apple Computer, Inc. 1988
- All Rights Reserved.
-
- 88/11/08 BL°B First Version
-
- To compile and link this file using Macintosh Programmer's Workshop,
-
- C -q2 CDTrack.c
- link -sn Main=CDTrack -sn STDIO=CDTrack ∂
- -sn INTENV=CDTrack -rt XFCN=42 ∂
- -m CDTrack CDTrack.c.o "{CLibraries}"CRuntime.o ∂
- "{CLibraries}"StdCLib.o ∂
- -o HyperCommands
-
- This link directive puts the XCMD in the file "HyperCommands".
- Substitute the name of the stack you want it in. To move XCMDs
- between stacks, use ResEdit. They can be in an individual stack,
- the Home stack, the HyperCard application, or the System File.
-
- */
-
- #include <cd.h>
-
- /* prototype definitions for functions */
- OSErr ATrack(short, short *);
- OSErr ReadQ(short, short *, short *, short *, short *);
-
- /* **** WARNING: DO NOT USE GLOBAL VARIABLES! **** */
-
-
- /************************************************************************
- *
- * Function: CDTrack
- *
- * Purpose: return the number of tracks on this disc.
- *
- * Returns: either the number of tracks, or an error
- * if it's a negative number, it's an error
- *
- * Side Effects:
- *
- * Description: We need no parameter:
- * Get the ioRefNum that we got from previously calling
- * CDOpen() from accessing a famous global.
- * call the driver with a READTOC call to find out
- * how many tracks there are.
- *
- ************************************************************************/
- pascal void
- CDTrack(paramPtr)
- XCmdBlockPtr paramPtr;
- {
- Str31 returnString;
- OSErr result;
- short ioRefNum;
- Handle refHandle;
- short numberTracks;
- short trackNo, minute, second, block;
- long args[2];
-
- /* Must be no parameter */
- if ((paramPtr->paramCount) != 0)
- {
- /* Report error in parameters by returning -1 */
- NumToStr(paramPtr, (long) -1, &returnString);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- return;
- }
-
- /* Get the global ioRefNum and convert it. */
- refHandle = GetGlobal(paramPtr, GLOBALNAME);
- ioRefNum = atoi(*(refHandle));
- DisposHandle(refHandle);
- ioRefNum &= 0xFFFF; /* remove vRefNum; not needed. */
-
- result = ATrack(ioRefNum, &numberTracks);
-
- if (result == noErr)
- result = ReadQ(ioRefNum, &trackNo, &minute, &second, &block);
-
- if (result == noErr)
- {
- args[0] = (long) trackNo;
- args[1] = (long) numberTracks;
- FormatString(&returnString, args, (long) 2);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- }
- else
- {
- /* We got an error. Convert result to string & return it as error */
- NumToStr(paramPtr, (long) result, &returnString);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- }
- }
-
- /************************************************************************
- *
- * Function: ATrack
- *
- * Purpose: report how many tracks are on this CD
- *
- * Returns: OSErr. Probably either
- * noErr everything's hunky-dory!
- * paramErr you messed up the call somehow.
- *
- * Side Effects: none
- *
- * Description: Simply call the driver.
- *
- ************************************************************************/
- OSErr
- ATrack(refNum, numberTracks)
- short refNum;
- short *numberTracks;
- {
- CDParam myPB;
- OSErr result;
-
- myPB.ioCompletion = 0;
- myPB.ioNamePtr = (char *) 0;
- myPB.ioVRefNum = 1;
- myPB.ioCRefNum = refNum;
- myPB.csCode = READTOC;
- myPB.csParam[0] = 0;
- myPB.csParam[1] = 1;
-
- result = PBControl(&myPB, false);
-
- if (result == noErr)
- *numberTracks = (short) BCD2DECIMAL(myPB.csParam[1]);
- return result;
- }
-
-
- /************************************************************************
- *
- * Function: ReadQ
- *
- * Purpose: return current Q subcode address data
- *
- * Returns: OSErr. Probably either
- * noErr everything's hunky-dory!
- * paramErr you messed up the call somehow.
- *
- * Side Effects: none
- *
- * Description: Simply call the driver. Return track number and
- * absolute minute, second, block.
- *
- ************************************************************************/
- OSErr
- ReadQ(refNum, trackNo, minute, second, block)
- short refNum;
- short *trackNo;
- short *minute;
- short *second;
- short *block;
- {
- CDParam myPB;
- OSErr result;
-
- myPB.ioCompletion = 0;
- myPB.ioNamePtr = (char *) 0;
- myPB.ioVRefNum = 1;
- myPB.ioCRefNum = refNum;
- myPB.csCode = READQ;
-
- result = PBControl(&myPB, false);
-
- if (result == noErr)
- {
- *trackNo = (short) BCD2DECIMAL(myPB.csParam[1]);
- *minute = (short) BCD2DECIMAL(myPB.csParam[6]);
- *second = (short) BCD2DECIMAL(myPB.csParam[7]);
- *block = (short) BCD2DECIMAL(myPB.csParam[8]);
- }
- return result;
- }
-
-
-
- /* C routines for HyperCard callbacks */
- #include <XCmdGlue.inc.c>
-